Skip to content

feat(setup): copy wizard code blocks with c - #771

Open
ffantl-ld wants to merge 1 commit into
ffantl/setup-ld/6-commandfrom
ffantl/REL-15243/copy-snippet
Open

feat(setup): copy wizard code blocks with c#771
ffantl-ld wants to merge 1 commit into
ffantl/setup-ld/6-commandfrom
ffantl/REL-15243/copy-snippet

Conversation

@ffantl-ld

@ffantl-ld ffantl-ld commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

REL-15243, under the CLI Onboarding Wizard A/B epic (REL-15183).

Stacked on #753, which introduces cmd/setup.

Describe the solution you've provided

  • Add a c keybinding at the wizard's final screen that copies the raw init snippet — or the install command, when there is no snippet — to the system clipboard via OSC 52
  • Label the action next to the code block and confirm it once copied, so the key is discoverable and its effect visible
  • Inject the clipboard writer on wizardModel so tests assert the emitted sequence instead of writing to the terminal

The code block is drawn with a left gutter bar, so selecting it with the mouse copies the gutter characters and the padding lipgloss squares the block off with, and pasting that fails on every line. The wizard also runs in the alternate screen, so the snippet is not in scrollback once it exits — the copy has to happen while the TUI is live, which is exactly when the gutter is in the way.

Known limitation: OSC 52 support cannot be detected, and some terminals (including Apple Terminal) do not implement it. There, c reports success while the clipboard is untouched.

Describe alternatives you've considered

  • Removing the gutter bar so mouse selection copies cleanly. Rejected: it gives up the visual distinction between copy-me code and prose, and still copies the leading padding.
  • Printing the snippet unstyled after the wizard exits, so it lands in scrollback. Complementary rather than alternative, and it also covers the terminals that ignore OSC 52 — worth doing, but a separate change.

Additional context

github.com/charmbracelet/x/ansi moves from an indirect to a direct dependency for SetSystemClipboard. It was already in the module graph via lipgloss; no new module is added.

Testing approaches

  • Six new tests in cmd/setup/copy_test.go: the copied payload is byte-for-byte the raw snippet (asserted by decoding the OSC 52 base64, and by asserting the rendered view does contain the gutter bar the copy does not), snippet preferred over install command when both show, fallback to the command, no write on screens with nothing to copy, hint switches to confirmation, and c still reaches the list filter while filtering.
  • go build ./..., go vet, gofmt, and go test ./... clean; 51 subtests in cmd/setup; golangci-lint passed via pre-commit.
  • Not verified against a real terminal: emitting OSC 52 requires a tty that interprets it, which this environment does not provide. Worth a manual check in iTerm2 or kitty before merge.

Note

Low Risk
Localized TUI keyboard handling and clipboard OSC output only; no auth, API, or persistence changes. Residual risk is UX-only where terminals without OSC 52 may show “copied” without updating the system clipboard.

Overview
Adds Press c to copy on the setup wizard’s final screen so users can grab init snippets or failed install commands without mouse-selecting gutter-decorated code blocks (alternate screen also hides scrollback).

Copy uses OSC 52 via ansi.SetSystemClipboard, writing through an injectable clipboard writer (os.Stdout in production) so tests can assert the raw payload. copyableContent prefers the init snippet over the install command when both apply; copyHint switches from “Press c…” to “Copied…” after a successful keypress. c is ignored when there’s nothing to copy and still passes through to list filtering like q and h.

Six tests in copy_test.go cover OSC 52 encoding, preference/fallback, no-op cases, hint text, and filter behavior. github.com/charmbracelet/x/ansi is promoted to a direct go.mod dependency.

Reviewed by Cursor Bugbot for commit e4811aa. Bugbot is set up for automated code reviews on this repo. Configure here.

Code blocks are drawn with a left gutter bar, so selecting one by hand copies the
gutter characters and the padding lipgloss squares the block off with. The wizard
also owns the alternate screen, so the snippet is not in scrollback once it exits.

Pressing c writes the raw content to the system clipboard with OSC 52, preferring
the snippet over the install command when a screen shows both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant